package com.scuec.trainingmanagementsys.service.impl;

import com.scuec.trainingmanagementsys.entity.Project;
import com.scuec.trainingmanagementsys.entity.Team;
import com.scuec.trainingmanagementsys.mapper.ProjectMapper;
import com.scuec.trainingmanagementsys.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ProjectServiceImpl implements ProjectService {

    @Autowired
    private ProjectMapper projectMapper;

    @Override
    public Integer addProject(Project project) {
        // 修改：返回项目ID
        projectMapper.insert(project);
        return project.getProjectId();  // MyBatis会回填生成的ID
    }

    @Override
    public int deleteProject(Integer projectId) {
        return projectMapper.deleteById(projectId);
    }

    @Override
    public int updateProject(Project project) {
        return projectMapper.update(project);
    }

    @Override
    public Project getProject(Integer projectId) {
        return projectMapper.selectById(projectId);
    }

    @Override
    public List<Project> getAllProjects() {
        return projectMapper.selectAll();
    }

    @Override
    public int getProjectCount() {
        return projectMapper.getProjectCount();
    }

    @Override
    public List<Project> getProjectsByTeacherId(Integer teacherId) {
        return projectMapper.selectByTeacherId(teacherId);
    }

    @Override
    public List<Project> searchProjectsByName(String projectName) {
        return projectMapper.selectByProjectName(projectName);
    }

    @Override
    public int updateProjectStatus(Integer projectId, String status) {
        return projectMapper.updateProjectStatus(projectId, status);
    }
    // 实现新增方法：获取项目下所有小组
    @Override
    public List<Map<String, Object>> getTeamsByProjectId(Integer projectId) {
        return projectMapper.getTeamsByProjectId(projectId);
    }

    @Override
    public int batchDeleteProjects(List<Integer> ids) {
        return projectMapper.batchDelete(ids);
    }
    @Override
    public List<Project> getProjectList() {
        return projectMapper.getProjectList();
    }

}